<template>
    <z-paging ref="paging" v-model="addressList" @query="queryList">
        <u-sticky>
            <hedsty :mrbot="'45'"  :headCentext="'我的地址'" ></hedsty>
        </u-sticky>
        <view class="list_box" style="background-image: url('https://morgan.dingxians.cn/static/copup/3.png');"
            v-for="(item, index) in addressList" :key="index" @click="selAddress(item)">
            <view class="dizhiname_box">{{ item.province }}{{ item.city }}{{ item.area }}{{ item.detail }}</view>
            <view class="ismoren_box" v-if="item.status == 1">默认地址</view>
            <view class="name_box">{{ item.username }} {{ item.mobile }}</view>
            <view class="bianji" @click="$router('/userPage/address/editaddress?item=' + JSON.stringify(item))"
                style="background-image: url('https://morgan.dingxians.cn/static/address/1.png');"></view>
            <view class="shanchu" @click="deladress(item)"
                style="background-image: url('https://morgan.dingxians.cn/static/address/2.png');">
            </view>
        </view>
        <view class="invite_zs_box" @click="addRed">
            新增地址
        </view>

    </z-paging>
</template>
<script>
import hedsty from '../../components/hedsty.vue'
export default {
    components: {
        hedsty
    },
    data() {
        return {
            addressList: [],
            is_Back: false,
        }
    },
    onLoad(e) {
        this.is_Back = e.is_Back
    },
    onShow() {
        this.$refs.paging.reload()
    },
    methods: {
        queryList(pageNo, pageSize) {
            let data = {
                page: pageNo,
                limit: pageSize
            }
            this.$Request.get(this.$api.user.userAddress, data).then(res => {
                if (res.code == 200) {
                    this.$refs.paging.complete(res.data.data)
                }
            })
        },
        selAddress(item) {
            if (this.is_Back) {
                this.$store.state.orderDetail.user_address = item
                this.$goBack()
            }
        },
        addRed() {
            this.$router('/userPage/address/jionadd')
        },
        deladress(item) {
            let that = this
            uni.showModal({
                title: "确定删除？",
                success: function (res) {
                    if (res.confirm) {
                        that.$Request.del(that.$api.user.userAddress + `/${item.id}`).then(res => {
                            if (res.code == 200) {
                                that.$msg('删除成功')
                                that.$refs.paging.reload()
                            }
                        })
                    } else {
                        console.log('取消')
                    }
                }
            })
        }
    }
}
</script>
<style lang="scss" scoped>
.list_box {
    width: 690rpx;
    margin: auto;
    background-size: 100% 100%;
    padding: 35rpx 28rpx;
    box-sizing: border-box;
    position: relative;
    margin-bottom: 240rpx;

    .dizhiname_box {
        width: 100%;
        font-family: PingFang SC;
        font-weight: bold;
        font-size: 32rpx;
        color: #FFFFFF;
    }

    .ismoren_box {
        width: 110rpx;
        height: 36rpx;
        background: rgba(255, 255, 255, .05);
        border-radius: 5rpx;
        font-family: PingFang SC;
        font-weight: 500;
        font-size: 20rpx;
        text-align: center;
        color: #F6385C;
        line-height: 36rpx;
        margin-bottom: 29rpx;
    }

    .name_box {
        height: 19rpx;
        font-family: PingFang SC;
        font-weight: 500;
        font-size: 24rpx;
        color: #FFFFFF;
        line-height: 18rpx;
    }

    .bianji {
        width: 30rpx;
        height: 30rpx;
        background-size: 100% 100%;
        position: absolute;
        right: 40rpx;
        bottom: 41rpx;
    }

    .shanchu {
        width: 30rpx;
        height: 32rpx;
        background-size: 100% 100%;
        position: absolute;
        right: 110rpx;
        bottom: 41rpx;
    }
}

.invite_zs_box {
    position: fixed;
    width: 654rpx;
    height: 100rpx;
    background: rgba(239, 31, 31, 1);
    border-radius: 50rpx;
    text-align: center;
    line-height: 100rpx;
    font-family: PingFang SC;
    font-weight: bold;
    font-size: 36rpx;
    color: #FFFFFF;
    bottom: 40rpx;
    left: 0;
    right: 0;
    margin: auto;
}
</style>